package com.kunbo.cn.app.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.kunbo.cn.app.service.AppUserService;
import com.kunbo.cn.util.retu.BuildBean;
import com.kunbo.cn.util.retu.ResultBean;

/**
 * app 用户
 * @author  编写人:刘义
 * @date 时间:2019年2月23日下午1:18:48
 */
@RestController
@RequestMapping("/user")
public class UserAppController {
	
	@Autowired
	private AppUserService user;
	
	/**
	 * 用户登录
	 * @param userName
	 * @param password
	 * @return
	 */
	@PostMapping("/login")
	public ResultBean<Map<String, Object>> login(
			@RequestParam("userName")String userName,
			@RequestParam("password")String password,
			@RequestParam("userType")String userType
			){
		ResultBean<Map<String, Object>> result = new ResultBean<Map<String, Object>>();
		return BuildBean.buildResult(result, "success", "error", user.login(userName,password,userType));
	}
	
	
	
	
	/**
	 * 手机短信验证
	 * @param phone
	 * @return
	 */
	@PostMapping("/validatePhone")
	public ResultBean<String> validatePhone(
			@RequestParam("phone")String phone
			){
		ResultBean<String>  result = new ResultBean<String>();
		return BuildBean.buildResult(result, "success", "error", user.validatePhone(phone));
	}
	
	
	/**
	 * 设置新密码
	 * @param phone
	 * @param password
	 * @return
	 */
	@PostMapping("/setNewPassword")
	public ResultBean<Boolean> setNewPassword(
			@RequestParam("phone")String phone,
			@RequestParam("password")String password,
			@RequestParam("userType")String userType
			){
		ResultBean<Boolean>  result = new  ResultBean<Boolean>();
		return BuildBean.buildResult(result, "success", "error", user.setNewPassword(phone,password,userType));
	}
	
	/**
	 * 修改密码
	 * @param oldPassword
	 * @param newPassword
	 * @return
	 */
	@PostMapping("/setPassowrd")
	public ResultBean<Boolean> setPassowrd(
			@RequestParam("oldPassowrd")String oldPassword,
			@RequestParam("newPassword")String newPassword,
			@RequestParam("userType")String userType
			){
		ResultBean<Boolean>  result = new  ResultBean<Boolean>();
		return BuildBean.buildResult(result, "success", "error", user.setPassword(oldPassword,newPassword,userType));
	}
	
	
	/**
	 * 修改绑定手机号
	 * @param oldPhone
	 * @param newPhone
	 * @return
	 */
	@PostMapping("/setNewPhone")
	public ResultBean<Boolean> setNewPhone(
			@RequestParam("oldPhone")String oldPhone,
			@RequestParam("newPhone")String newPhone,
			@RequestParam("userType")String userType
			){
		ResultBean<Boolean>  result = new  ResultBean<Boolean>();
		return BuildBean.buildResult(result, "success", "error", user.setNewPhone(oldPhone,newPhone,userType));
	}
	

}
